package es.jclm.agri.foragri.domain;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuModel;
import org.springframework.stereotype.Component;
  
@Component
public class MenuBean {  
  
    private MenuModel model;  
  
    public MenuBean() {  
        model = new DefaultMenuModel();  
          
        //First submenu  
        DefaultSubMenu firstSubmenu = new DefaultSubMenu("Dynamic Submenu");  
          
        DefaultMenuItem item = new DefaultMenuItem("External");  
        item.setUrl("http://www.primefaces.org");  
        item.setIcon("ui-icon-home");  
        firstSubmenu.addElement(item);  
          
        model.addElement(firstSubmenu);  
          
        //Second submenu  
        DefaultSubMenu secondSubmenu = new DefaultSubMenu("Dynamic Actions");  
  
        item = new DefaultMenuItem("Save");  
        item.setIcon("ui-icon-disk");  
        item.setCommand("#{menuBean.save}");  
        item.setUpdate("messages");  
        secondSubmenu.addElement(item);  
          
        item = new DefaultMenuItem("Delete");  
        item.setIcon("ui-icon-close");  
        item.setCommand("#{menuBean.delete}");  
        item.setAjax(false);  
        secondSubmenu.addElement(item);  
          
        item = new DefaultMenuItem("Redirect");  
        item.setIcon("ui-icon-search");  
        item.setCommand("#{menuBean.redirect}");  
        secondSubmenu.addElement(item);  
  
        model.addElement(secondSubmenu);  
    } 
     
    public MenuModel getModel() {  
        return model;  
    }     
      
    public void save() {  
        addMessage("Data saved");  
    }  
      
    public void update() {  
        addMessage("Data updated");  
    }  
      
    public void delete() {  
        addMessage("Data deleted");  
    }  
  
    public String redirect() {  
        return "home?faces-redirect=true";  
    }  
     
    public void mensajeInfo(){
    	addMessageInfo("Mensaje informativo");
    }
    
    public void mensajeWarn(){
    	addMessageWarn("Mensaje warning");
    }
    
    public void mensajeError(){
    	addMessageError("Mensaje error");
    }
    
    public void mensajeFatal(){
    	addMessageFatal("Mensaje fatal");
    }
    
    
    public void addMessage(String summary) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null);  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    }  
    
    public void addMessageInfo(String summary) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_INFO, summary,  null);  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    } 
    
    public void addMessageWarn(String summary) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_WARN, summary,  null);  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    }
    public void addMessageError(String summary) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_ERROR, summary,  null);  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    } 
    public void addMessageFatal(String summary) {  
        FacesMessage message = new FacesMessage(FacesMessage.SEVERITY_FATAL, summary,  null);  
        FacesContext.getCurrentInstance().addMessage(null, message);  
    } 

    
} 
